package exercise;

import JZOffer.TreeNode;

public class LCR145 {
    public boolean checkSymmetricTree(TreeNode root) {
        if (root == null) {
            return true;
        }

        return check(root.left, root.right);
    }

    private boolean check(TreeNode left, TreeNode right) {
        if (left == null && right != null || right == null && left != null) {
            return false;
        }
        if (left == null && right == null) {
            return true;
        }
        if (left.val != right.val) {
            return false;
        }

        return check(left.left, right.right) && check(left.right, right.left);
    }

    public static void main(String[] args) {
        LCR145 lcr145 = new LCR145();

        TreeNode root = new TreeNode(6);
        root.left = new TreeNode(7);
        root.right = new TreeNode(7);
        root.left.left = new TreeNode(8);
        root.left.right = new TreeNode(9);
        root.right.left = new TreeNode(9);
        root.right.right = new TreeNode(8);

        System.out.println(lcr145.checkSymmetricTree(root));
    }
}
